﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.ComponentModel.DataAnnotations;

namespace DomainModel.Entities
{
    [Table(Name = "vUser")]
    public class vUser
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public Int32 UserID { get; set; }

        [Column]
        public String Login { get; set; }

        [Column]
        public String Password { get; set; }

        [Column]
        public String Email { get; set; }


        [Column]
        public String Organization { get; set; }

        [Column]
        public String Surname { get; set; }

        [Column]
       public String Name { get; set; }

        [Column]
        public String Patro { get; set; }

        [Column]
        public String Phone { get; set; }

        [Column]
        public Int32 rf_RoleID { get; set; }

        [Column]
        public Int32 rf_UserID { get; set; }

        [Column]
        public String RoleName { get; set; }

        [Column]
        public String ManagerName { get; set; }

        [Column]
        public String ManagerMail { get; set; }


        [Column]
        public Decimal Ratio { get; set; }


        public string FIO
        {
            get { return string.Format("{0} {1} {2}", Surname, Name, Patro); }
            set
            {
                string[] ss = value.Split(' ');
                Surname = ss[0];
                Name = ss[1];
                string s = string.Empty;
                for (int i = 2; i < ss.Length; i++)
                {
                    s += ss[i] + ' ';
                }
                Patro = s.Trim();
            }
        }

        [Column]
        public bool isFinVisible { get; set; }


        public bool IsAdmin
        {
            get { return rf_RoleID == 1; }
        }

        public bool IsManager
        {
            get { return rf_RoleID == 2; }
        }

        public bool IsClient
        {
            get { return rf_RoleID == 3; }
        }

        public vUser()
        {

        }
    }
}
